#include <stdio.h>
#include <stdlib.h>

void overTurn();
void shortCutProcess();
int isPrime(int);
void primeCount();
void pascalTriangle();

#ifdef __linux__
    #define pause "read -p \"Press <Enter> to continue...\" tmpVar"
#elif _WIN32
    #define pause "pause"
#elif __APPLE__
    #define pause "echo -e Press any key to continue... && read -n 1"
#endif

int main() {
    overTurn();
    system(pause);
    shortCutProcess();
    system(pause);
    primeCount();
    system(pause);
    pascalTriangle();
    return 0;
}

void overTurn() {
    int a[100];
    int i = 0, j = 0, n;
    printf("Enter n (n <= 100):\t");
    scanf("%d", &n);
    getchar();
    printf("Enter the number:\t");
    for(i = 0; i < n; i ++)
        scanf("%d", &a[i]);
    getchar();
    int b[100];
    for(j = 0; j < n; j ++)
        b[n-j-1] = a[j];
    printf("The list is:\t[");
    for(j = 0; j < n; j ++)
        printf("%d, ", b[j]);
    printf("]\n");
}

void shortCutProcess() {
    int a[100];
    int i, j = 0, n;
    int b[100];
    printf("Enter n (n <= 100):\t");
    scanf("%d", &n);
    printf("Enter the number:\t");
    for(i = 0; i < n; i ++)
        scanf("%d", &a[i]);
    for(i = 0; i < n; i ++)
        if(i % 2) {
            b[j] = a[i];
            j ++;
        }
    printf("The list is:\t[");
    for(i = 0; i < j; i ++)
        printf("%d, ", b[i]);
    printf("]\n");
}

int isPrime(int num) {
    int i, j;
    for(i = 2; i < num; i ++) {
        if( !(num % i))
            return 0;
    }
    return 1;
}

void primeCount() {
    int i, n = 0;
    int judge;
    printf("primes of 101~200:\t[");
    for(i = 101; i < 201; i ++) {
        judge = isPrime(i);
        if(judge) {
            printf("%d, ", i);
            n ++;
        }
    }
    printf("]\nCount of them:\t%d\n", n);
}

void pascalTriangle() {
    int num;
    printf("Enter the num (num <= 13):\t");
    scanf("%d", &num);
    int a [num][num], i, j;
    for (i = 0; i < num; i++) {
        for (j = 0;j <= num-i; j++)
            printf ("  ");
        for (j = 0; j <= i; j++)
            printf("%4d", (a[i][j] = (i == j || j == 0) ? 1 : a[i - 1][j] + a[i - 1][j - 1] )); 
        printf("\n");
    }
    getchar();
}
